package com.atao.example.stream03;

import java.util.stream.Stream;

/**
 * @author 阿涛
 * @date 2021-03-07
 */
public class Test {
    public static void main(String[] args) {
        /**
         * 1. 延迟方法 放回仍然是流
         * 2. 终结方法 返回void或者是非流
         */
        Stream<String> stream = Stream.of("三七", "人参", "鹿茸", "紫河车");
        //todo 如果stream只能使用一次
//        System.out.println("一共"+stream.count()+"味中药");
        stream.forEach(medicine-> System.out.println(medicine));
        System.out.println("======================================");

        //todo stream map
        Stream<String> stream1 = Stream.of("12", "2", "3", "22");
//        stream1.map(somethine->Integer.parseInt(somethine)).forEach(something-> System.out.println(something));
        stream1.map(somethine->Integer.parseInt(somethine)).forEach(System.out::println);
        System.out.println("======================================");

        //todo stream limit
        Stream<String> stream2 = Stream.of("12", "2", "3", "22");
        stream2.map(Integer::parseInt).limit(3).forEach(System.out::println);
        System.out.println("======================================");

        //todo stream skip
        Stream<String> stream3 = Stream.of("12", "2", "3", "22");
        stream3.map(Integer::parseInt).limit(3).skip(2).forEach(System.out::println);
        System.out.println("======================================");

        Stream.concat(Stream.of(1,2,2,3), Stream.of(2,3,303003003)).forEach(System.out::println);

    }
}
